package com.lcx.myservice;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {
    private final String TAG = "lcx_debug MyService";
    MediaPlayer mediaPlayer1;
    public MyService() {
    }

    @Override
    public void onCreate() {
        Log.d(TAG, "onCreate: ");
        Toast.makeText(this, "MyServiceCreate", Toast.LENGTH_SHORT).show();
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        if (mediaPlayer1 != null) {
            mediaPlayer1.release();
            mediaPlayer1 = null;
        }
        Toast.makeText(this, "MyServiceDestroy", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "onDestroy: ");
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Toast.makeText(this, "MyServiceStart", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "onStartCommand: ");
        if (intent.getExtras().get("music").equals("R.raw.face"))
        {
            mediaPlayer1 = MediaPlayer.create(this, R.raw.face);
            mediaPlayer1.start();
        }

        return START_STICKY;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.d(TAG, "onUnbind: ");
        return super.onUnbind(intent);
    }

    @Override
    public IBinder onBind(Intent intent) {
        Log.d(TAG, "onBind: ");
        // TODO: Return the communication channel to the service.
       return null;
    }
}